<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    const str = 'abcdefgggddssabc';
    /**
     * 期望结果
     * {
     *  a: 2,
     *  b: 2,
     *  c: 2,
     *  d: 3,
     *  e: 1,
     *  f: 1,
     *  g: 3,
     *  s: 2
     * }
     */  
    const container = {};
    str.split('').forEach((k, i) => {
      container[k] = container[k] === undefined ? 1 : (container[k] + 1);
    });
    let mostLabel = '';
    let max = 0;
    for (key in container) {
      console.log(key);
      if (max < container[key]) {
        max = container[key];
        mostLabel = key;
      }
    }
    document.write(`字符出现最多的是${mostLabel}，次数为${max}`);
  </script>
</body>
</html>